package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 判断题实体类
 * 对应数据库表：true_false_question_base
 *
 * 根据B-02-03-06判断题管理子模块设计文档实现
 * 管理判断题的基础信息，包括题目内容、选项配置、解析说明等。
 * 支持二元选择结构（正确/错误）的判断题管理。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "true_false_question_base")
@Comment("判断题主表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TrueFalseQuestion {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 题目唯一标识符
     */
    @NotBlank(message = "题目ID不能为空")
    @Size(max = 50, message = "题目ID长度不能超过50个字符")
    @Column(name = "question_id", nullable = false, length = 50, unique = true)
    private String questionId;

    /**
     * 题目编号（格式：TF-YYYY-NNN）
     */
    @NotBlank(message = "题目编号不能为空")
    @Size(max = 32, message = "题目编号长度不能超过32个字符")
    @Column(name = "question_code", nullable = false, length = 32, unique = true)
    private String questionCode;

    /**
     * 题目标题
     */
    @NotBlank(message = "题目标题不能为空")
    @Size(max = 200, message = "题目标题长度不能超过200个字符")
    @Column(name = "title", nullable = false, length = 200, unique = true)
    private String title;

    /**
     * 题目分类ID
     */
    @Column(name = "category_id")
    private Long categoryId;

    /**
     * 科目ID
     */
    @Column(name = "subject_id")
    private Long subjectId;

    /**
     * 题目内容
     */
    @NotBlank(message = "题目内容不能为空")
    @Column(name = "content", nullable = false, columnDefinition = "TEXT")
    private String content;

    /**
     * 题目解析说明
     */
    @Column(name = "explanation", columnDefinition = "TEXT")
    private String explanation;

    /**
     * 题目难度级别（1-简单，2-中等，3-困难）
     */
    @NotNull(message = "难度级别不能为空")
    @Column(name = "difficulty_level", nullable = false)
    private Integer difficultyLevel;

    /**
     * 题目总分
     */
    @NotNull(message = "题目总分不能为空")
    @Column(name = "total_score", nullable = false, precision = 5, scale = 2)
    private BigDecimal totalScore;

    /**
     * 答题时间限制（秒）
     */
    @Column(name = "time_limit_seconds")
    private Integer timeLimitSeconds;

    /**
     * 题目状态（DRAFT-草稿，PENDING-待审核，APPROVED-已通过，PUBLISHED-已发布，REJECTED-已拒绝，ARCHIVED-已归档）
     */
    @NotBlank(message = "题目状态不能为空")
    @Size(max = 20, message = "题目状态长度不能超过20个字符")
    @Column(name = "status", nullable = false, length = 20)
    private String status;

    /**
     * 版本号
     */
    @NotNull(message = "版本号不能为空")
    @Column(name = "version_number", nullable = false)
    private Integer versionNumber;

    /**
     * 质量评分（0-100分）
     */
    @Column(name = "quality_score", precision = 5, scale = 2)
    private BigDecimal qualityScore;

    /**
     * 使用次数
     */
    @Column(name = "usage_count")
    private Integer usageCount;

    /**
     * 知识点
     */
    @Column(name = "knowledge_points", columnDefinition = "TEXT")
    private String knowledgePoints;

    /**
     * 题目标签（JSON格式）
     */
    @Column(name = "tags", columnDefinition = "TEXT")
    private String tags;

    /**
     * 选项配置（JSON格式，包含正确答案）
     */
    @Column(name = "option_config", columnDefinition = "TEXT")
    private String optionConfig;

    /**
     * 适用年级
     */
    @Size(max = 50, message = "适用年级长度不能超过50个字符")
    @Column(name = "grade_level", length = 50)
    private String gradeLevel;

    /**
     * 题目来源（ORIGINAL-原创，IMPORT-导入，CONTRIBUTION-贡献）
     */
    @Size(max = 30, message = "题目来源长度不能超过30个字符")
    @Column(name = "question_source", length = 30)
    private String questionSource;

    /**
     * 正确答案标识（true-正确，false-错误）
     */
    @NotNull(message = "正确答案标识不能为空")
    @Column(name = "correct_answer", nullable = false)
    private Boolean correctAnswer;

    /**
     * 答案反馈信息
     */
    @Column(name = "answer_feedback", columnDefinition = "TEXT")
    private String answerFeedback;

    /**
     * 错误答案反馈信息
     */
    @Column(name = "incorrect_feedback", columnDefinition = "TEXT")
    private String incorrectFeedback;

    /**
     * 是否显示即时反馈
     */
    @NotNull(message = "即时反馈设置不能为空")
    @Column(name = "show_immediate_feedback", nullable = false)
    private Boolean showImmediateFeedback;

    /**
     * 是否随机显示选项
     */
    @NotNull(message = "随机选项设置不能为空")
    @Column(name = "randomize_options", nullable = false)
    private Boolean randomizeOptions;

    /**
     * 扩展属性（JSON格式）
     */
    @Column(name = "extended_properties", columnDefinition = "TEXT")
    private String extendedProperties;

    /**
     * 创建者ID
     */
    @NotBlank(message = "创建者ID不能为空")
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "creator_id", nullable = false, length = 50)
    private String creatorId;

    /**
     * 审核者ID
     */
    @Size(max = 50, message = "审核者ID长度不能超过50个字符")
    @Column(name = "reviewer_id", length = 50)
    private String reviewerId;

    /**
     * 发布者ID
     */
    @Size(max = 50, message = "发布者ID长度不能超过50个字符")
    @Column(name = "publisher_id", length = 50)
    private String publisherId;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    /**
     * 发布时间
     */
    @Column(name = "publish_time")
    private LocalDateTime publishTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;
}